﻿$(function () {
    BindScoreHistory();
    $("#btnSaveScore").click(SaveEvaluation);
}
);
var appId;
//绑定评分列表
function BindScoreHistory() {
    var snapGuid = $("#hdSnapGuid").val();
    var corpUserGuid = $("#hdCorpUserGuid").val();
  
    $("#tblScoreList tbody").empty();
    $.getJSON("../Handlers/KaoHeHandler.ashx", { "action": "GetEvaluationScoreList", "snapGuid": snapGuid, "corpUserGuid": corpUserGuid, "rand": Math.random() }, function (data) {
        if (data) {
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                var tr = "<tr style='cursor: pointer;' onclick=\"showScore(this," + item.Id + ",'" + item.IsrtUserGuid + "')\">";
                tr += "<td>" + item.IsrtName + "</td>";
                tr += "<td>" + DateFormatConvert(item.IsrtDate) + "</td>";
                tr += "<td>" + item.TotalScore + "</td>";
                tr += "<td style=' display:none'>A</td>";
                tr += "</tr>";
                $("#tblScoreList tbody").append(tr);
            }
        }
        
    }
    );
}

//评分汇总
function SaveEvaluation() {
    var result = true;
    $(".fenshu", "#tagContent").each(function () {
        if ($.trim($(this).val()) != "") {
            if (!checkScoreData($.trim($(this).val()))) {
                alert("分值只能输入正数！");
                result = false;
                return false;
            }
        }
    });
    if (result) {
        var snapGuid = $("#hdSnapGuid").val();
        var corpUserGuid = $("#hdCorpUserGuid").val();
        var classId = 8010;
        var appId = $("#hdAppId").val();
        var isrtUserGuid = "";
        $.getJSON("../Handlers/KaoHeHandler.ashx", { "action": "SaveEvaluation", "snapGuid": snapGuid, "corpUserGuid": corpUserGuid, "isrtUserGuid": isrtUserGuid, "classId": classId, "appId": appId, "rand": Math.random() }, function (data) {
            alert(data.Message);
            if (data.Result) {
                //刷新评分列表
                BindScoreHistory();
            }
        });
    }
}

//日期格式转化
function DateFormatConvert(date) {
    var dateStr = date;
    if (typeof date == "object") {
        dateStr = date.toLocaleString();
    } else if (typeof date == "string") {
        dateStr = date;
    }
    return dateStr.replace(/^([\d-]+)T([\d:]+).+$/, "$1 $2");
}

function showScore(trId,evalustionId, isrtUserGuid) {
    $("#hdEvaluationItemId").val(evalustionId);
    $("#hdIsrtUserGuid").val(isrtUserGuid);
    $(trId).parent().find("tr").removeAttr("bgColor");
    $(trId).attr("bgColor", "#dcdcdc");
    GetCorpEvaluationItems();
}